package com.qingke.hello;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public MyServlet() {
        super();
    }
    
    public void init(ServletConfig config) throws ServletException {
    	System.out.println("aaa");
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("hello");
		String username = request.getParameter("username");
		String password= request.getParameter("password");
		String message = "";
		if(username == null || username.trim().equals("")) {
			message = "用户名为空";
		} else {
			message = "用户名：" + username;
		}
		
		if(password == null || password.trim().equals("")) {
			message = message + ",密码为空";
		} else {
			message = "密码：" + password;
		}
		
		PrintWriter pw = response.getWriter();
		response.setCharacterEncoding("utf-8");
		pw.println("<!doctype html>");
		pw.println("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
		pw.println("<head></head>");
		pw.println("<body><p>'" + message + "'</p></body></html>");
		pw.close();
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	
	public void destroy() {
		
	}

}
